package com.search;



import com.search.config.FxInjectConfig;
import javafx.application.Application;
import javafx.application.HostServices;
import javafx.stage.Stage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.ConfigurableApplicationContext;

import java.io.File;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

@SpringBootApplication
public class FxApplication extends Application {
    // 任何地方都可以通过这个applicationContext获取springboot的上下文
    public static ConfigurableApplicationContext applicationContext;
    public static String[] args;
    public static HostServices hostServices;
    public  static String jardir="";
    public  static String chromedriver=jardir+"lib"+File.separator+"chromedriver.exe";


    @Override
    public void start(Stage stage) throws Exception {
        FxInjectConfig bean = applicationContext.getBean(FxInjectConfig.class);
        bean.initStage(stage,null);
        hostServices = getHostServices(); // 获取浏览器对象
    }
    @Override
    public void init() throws Exception {
        //linux和windows下通用
        ApplicationHome home = new ApplicationHome(getClass());
        File jarFile = home.getSource();
        jardir = jarFile.getParentFile().toString()+File.separator;
        System.out.println("jardir路径："+jardir);
        // 启动springboot
        applicationContext = SpringApplication.run(FxApplication.class, args);
        System.out.println("springboot 启动成功");

    }

    @Override
    public void stop() throws Exception {
        // 关闭springboot
        applicationContext.stop();
    }

}
